﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EECMISWS;
using System.IO;

namespace WebConfigManager.TabPageControls
{
    public partial class PageConfigClient : PageConfigBase
    {
        private WebClientConfig _config = new WebClientConfig();
        public WebClientConfig Config
        {
            get { return _config; }
        }

        public PageConfigClient()
        {
            InitializeComponent();
        }

        public override bool LoadConfig()
        {
            if (!File.Exists(WebSetting.IniFileName))
            {
                _config.Save();
            }
            else
            {
                _config.Load();
            }
            return true;
        }

        public override bool InitCtrls()
        {
            textBoxDWBH.Text = _config.TBDWBH;
            textBoxDWMC.Text = _config.Client_DWMC;
            textBoxIP.Text = _config.Client_IP;
            textBoxSFZH.Text = _config.Client_SFZH;
            textBoxXM.Text = _config.Client_XM;
            textBoxZSBH.Text = _config.Client_ZSBH;
            textBoxCityCode.Text = _config.CityCode;
            return true;
        }

        public override bool UpdateData()
        {
            if (string.IsNullOrEmpty(textBoxDWBH.Text))
            {
                MessageBox.Show("单位编号必须填写不能为空!", "配置错误");
                return false;
            }

            if (textBoxDWBH.Text.Length < 6)
            {
                MessageBox.Show("单位编号长度不正确，请检查重新输入!", "配置错误");
                return false;
            }

            _config.TBDWBH = textBoxDWBH.Text;
            _config.Client_DWMC = textBoxDWMC.Text;
            _config.Client_IP = textBoxIP.Text;
            _config.CityCode = textBoxCityCode.Text;
            _config.Client_SFZH = textBoxSFZH.Text;
            _config.Client_XM = textBoxXM.Text;
            _config.Client_ZSBH = textBoxZSBH.Text;
            _config.Save();
            return true;
        }

    }
}
